package com.xiaoyu.commonlib.ui;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.xiaoyu.commonlib.CommonPlug;
import com.xiaoyu.commonlib.utils.ToastUtil;

/**
 * Created by jk on 2018/5/3.
 */
public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
    private int space;
    private int direction;//0:四边都加边距，1:上、下加边距，2:左、右加边距

    public SpacesItemDecoration(int space) {
        this.space = space;
        this.direction = 0;
    }

    public SpacesItemDecoration(int space, int direction) {
        this.space = space;
        this.direction = direction;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        if (direction == 0){
            outRect.left = space;
            outRect.right = space;
            outRect.top = space;
            outRect.bottom = space;
        }else if (direction == 1){
            outRect.bottom = space;
        }else if (direction == 2){
            outRect.left = space;
            outRect.right = space;
        }else if (direction == 3){
            outRect.bottom = space;
            outRect.right = space;
        }


    }
}












































